<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title>12.5.2 Acceleo 2 Queries</title>
		<link type="text/css" rel="stylesheet" href="PLUGINS_ROOT/org.polarsys.capella.doc/html/styles.css"/>
	</head>
	<body>
		<h1 id="Aql_queries">Aql queries</h1>
		<h2 id="Basic_Model_Queries">Basic Model Queries</h2>
		<table cellpadding="7">
			<tr>
				<th>
					<b>Description</b>
				</th>
				<th>
					<b>Workbench Selection</b>
				</th>
				<th>
					<b>Syntax</b>
				</th>
			</tr>
			<tr>
				<td>Current Element </td>
				<td>Model Element</td>
				<td>aql:self</td>
			</tr>
			<tr>
				<td>Container of current element</td>
				<td>A model element </td>
				<td>aql:self.
					<b>eContainer()</b>
				</td>
			</tr>
			<tr>
				<td>Type of an element</td>
				<td>A model element</td>
				<td>aql:self.
					<b>eClass()</b>
				</td>
			</tr>
			<tr>
				<td>Total number of elements in a model</td>
				<td>A model element</td>
				<td>aql:self.
					<b>ancestors()-&gt;last().eAllContents()-&gt;size()</b>
				</td>
			</tr>
			<tr>
				<td>Total number of sub-elements</td>
				<td>A model element</td>
				<td>aql:self.
					<b>eAllContents()-&gt;size()</b>
				</td>
			</tr>
		</table>
		<p>
			<br/>
		</p>
		<h2 id="Diagram_Queries">Diagram Queries</h2>
		<table cellpadding="7">
			<tr>
				<td>
					<b>Description</b>
				</td>
				<td>
					<b>Workbench Selection</b>
				</td>
				<td>
					<b>Syntax</b>
				</td>
			</tr>
			<tr>
				<td>Semantic element associated to a graphical element</td>
				<td>A diagram / A diagram element</td>
				<td>aql:self.
					<b>target</b>
				</td>
			</tr>
			<tr>
				<td>aird file (non fragmented model)</td>
				<td>A diagram</td>
				<td>aql:((self.makeUnion(self, self.eInverse(''))).ancestors()-&gt;select(ancestor &#124; ancestor.eClass().name = 'DAnalysis')-&gt;asSet())</td>
			</tr>
			<tr>
				<td>All aird files (fragmented model)</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis()</td>
			</tr>
			<tr>
				<td>All diagrams</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().
					<b>ownedViews.ownedRepresentationDescriptors</b>
				</td>
			</tr>
			<tr>
				<td>Number of diagrams</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().
					<b>ownedViews.ownedRepresentationDescriptors-&gt;size()</b>
				</td>
			</tr>
			<tr>
				<td>All diagrams from kind "Logical Data Flow"</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().
					<b>ownedViews.ownedRepresentationDescriptors-&gt;select(x &#124; x.description.name.startsWith('Logical Data Flow Blank'))</b>
				</td>
			</tr>
			<tr>
				<td>All diagrams except kind "Scenario"</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().
					<b>ownedViews.ownedRepresentationDescriptors-&gt;select(x &#124; x.description.name.endsWith('Scenario') = false)</b>
				</td>
			</tr>
			<tr>
				<td>List of different viewpoints</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().
					<b>ownedViews.viewpoint-&gt;asSet()</b>
				</td>
			</tr>
			<tr>
				<td>Number of graphical elements in all diagrams</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().
					<b>ownedViews.ownedRepresentationDescriptors.representation.diagramElements-&gt;size()</b>
				</td>
			</tr>
			<tr>
				<td>Number of graphical elements in all diagrams (including technical elements like style, color…)</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().
					<b>ownedViews.ownedRepresentationDescriptors.representation.eAllContents()-&gt;size()</b>
				</td>
			</tr>
		</table>
		<h2 id="Searching_Strings">Searching Strings</h2>
		<table cellpadding="7">
			<tr>
				<td>
					<b>Description</b>
				</td>
				<td>
					<b>Workbench Selection</b>
				</td>
				<td>
					<b>Syntax</b>
				</td>
			</tr>
			<tr>
				<td>All element containing the "TODO" string in their 'Name' property</td>
				<td>A model element</td>
				<td>aql:self.eAllContents()-&gt;
					<b>select(eAllContent &#124; eAllContent.name.matches('.*TODO.*'))</b>
				</td>
			</tr>
			<tr>
				<td>All element containing the "TODO" string in their 'Summary' property</td>
				<td>A model element</td>
				<td>aql:self.eAllContents()-&gt;
					<b>select(eAllContent &#124; eAllContent.summary.matches('.*TODO.*'))</b>
				</td>
			</tr>
			<tr>
				<td>All element containing the "TODO" string in their 'Description' property</td>
				<td>A model element</td>
				<td>aql:self.eAllContents()-&gt;
					<b>select(eAllContent &#124; eAllContent.description.matches('.*TODO.*'))</b>
				</td>
			</tr>
			<tr>
				<td>All diagrams containing a note containing the "TODO" string</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().ownedViews.ownedRepresentationDescriptors.
					<b>representation-&gt;select(x &#124; x.eInverse('element')-&gt;filter(notation::Diagram).eAllContents(notation::Node)-&gt;select(x &#124; x.type = 'Note' and x.description.contains('TODO')))</b>
				</td>
			</tr>
			<tr>
				<td>Number of diagrams containing a note containing the "TODO" string</td>
				<td>A diagram</td>
				<td>aql: self.getAllDAnalysis().ownedViews.ownedRepresentationDescriptors.
					<b>representation-&gt;select(x &#124; x.eInverse('element')-&gt;filter(notation::Diagram).eAllContents(notation::Node)-&gt;select(x &#124; x.type = 'Note' and x.description.contains('TODO')))-&gt;size()</b>
				</td>
			</tr>
		</table>
		<h2 id="Model_Navigation_Examples">Model Navigation Examples</h2>
		<table cellpadding="7">
			<tr>
				<td>
					<b>Description</b>
				</td>
				<td>
					<b>Workbench Selection</b>
				</td>
				<td>
					<b>Syntax</b>
				</td>
			</tr>
			<tr>
				<td>List of functions allocated to a component</td>
				<td>Any Component</td>
				<td>aql:self.allocatedFunctions</td>
			</tr>
			<tr>
				<td>List of sub logical components</td>
				<td>Any Logical Component</td>
				<td>aql:self.subLogicalComponents</td>
			</tr>
			<tr>
				<td>List of all functions
					<p>- having more than 3 ports
						- allocated to one given component
						- Which name starts with "Store"</p>
				</td>
				<td>Any Component</td>
				<td>aql:self.allocatedFunctions-&gt;select(allocatedFunction &#124; allocatedFunction.name.startsWith('Store') and allocatedFunction.eAllContents()-&gt;filter(fa::FunctionPort)-&gt;size() &gt; 3)</td>
			</tr>
		</table>
		<h2 id="Metrics">Metrics</h2>
		<table cellpadding="7">
			<tr>
				<td>
					<b>Description</b>
				</td>
				<td>
					<b>Workbench Selection</b>
				</td>
				<td>
					<b>Syntax</b>
				</td>
			</tr>
			<tr>
				<td>Number of YYYY::XXXX owned by the selected element, where XXXX is the type of a model element (aql:self.eClass() ) and YYYY the last term of its package</td>
				<td>A model element</td>
				<td>aql:self.eAllContents(YYYY::XXXX)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Operational Activities</td>
				<td>OperationalAnalysis</td>
				<td>aql:self.eAllContents(oa::OperationalActivity)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Operational Interactions</td>
				<td>OperationalAnalysis</td>
				<td>aql:self.eAllContents(fa::FunctionalExchange)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Exchange Items in OA</td>
				<td>OperationalAnalysis</td>
				<td>aql:self.eAllContents(modellingcore::AbstractExchangeItem)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Types (Classes, Datatypes) in OA</td>
				<td>OperationalAnalysis</td>
				<td>aql:self.eAllContents(datatype::DataType)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Classes in OA</td>
				<td>OperationalAnalysis</td>
				<td>
					<p>aql:self.eAllContents(information::Class)-&gt;size()</p>
				</td>
			</tr>
			<tr>
				<td>Number of States or Modes in OA</td>
				<td>OperationalAnalysis</td>
				<td>aql:(self.eAllContents()-&gt;filter(capellacommon::State) - self.eAllContents()-&gt;filter(capellacommon::Mode))-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Operational Entities</td>
				<td>OperationalAnalysis</td>
				<td>aql:(self.eAllContents(oa::Entity)-&gt;select(e &#124; not e.isActor()))-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Operational Actors</td>
				<td>OperationalAnalysis</td>
				<td>aql:(self.eAllContents(oa::Entity)-&gt;select(e &#124; e.isActor()))-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Operational Roles</td>
				<td>OperationalAnalysis</td>
				<td>aql:self.eAllContents(oa::Role)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Communication Means</td>
				<td>OperationalAnalysis</td>
				<td>aql:self.eAllContents(oa::CommunicationMean)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of System Functions</td>
				<td>SystemAnalysis</td>
				<td>aql:self.eAllContents(ctx::SystemFunction)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Functional Exchanges in SA</td>
				<td>SystemAnalysis</td>
				<td>aql:self.eAllContents(fa::FunctionalExchange)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Function Ports in SA</td>
				<td>SystemAnalysis</td>
				<td>aql:self.eAllContents()-&gt;filter(fa::FunctionPort)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of System Actors</td>
				<td>SystemAnalysis</td>
				<td>aql:(self.eAllContents(ctx::SystemComponent)-&gt;select(c &#124; c.isActor()))-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Functional Chains in SA</td>
				<td>SystemAnalysis</td>
				<td>aql:self.eAllContents(fa::FunctionalChain)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Scenarios in SA</td>
				<td>SystemAnalysis</td>
				<td>aql:self.eAllContents(interaction::Scenario)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Behaviour Components in PA</td>
				<td>PhysicalArchitecture</td>
				<td>aql:self.eAllContents(pa::PhysicalComponent)-&gt;select(eAllContent &#124; eAllContent.nature = pa::PhysicalComponentNature::BEHAVIOR)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Implementation PC (nodes) in PA</td>
				<td>PhysicalArchitecture</td>
				<td>aql:self.eAllContents(pa::PhysicalComponent)-&gt;select(eAllContent &#124; eAllContent.nature = pa::PhysicalComponentNature::NODE)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Physical Links</td>
				<td>PhysicalArchitecture</td>
				<td>aql:self.eAllContents(cs::PhysicalLink)-&gt;size()</td>
			</tr>
			<tr>
				<td>Number of Physical Ports</td>
				<td>PhysicalArchitecture</td>
				<td>aql:self.eAllContents(cs::PhysicalPort)-&gt;size()</td>
			</tr>
		</table>
		<h2 id="Advanced_Queries">Advanced Queries</h2>
		<p>With Aql, you can navigate in elements following references and attributes:
			aql:self.outgoing on a SystemFunction will retrieve outgoing functional exchanges:
			<br/>
			<br/>

			<img height="150" width="500" border="0" src="Images/12_5_ Acceleo Queries_html_51a25b.png"/>
			<br/>

			<br/>
			There is many way to retrieve which references to use for an element. These references ca be used in a request like the above outgoing reference.
			For instance, you can retrieve references with Aql using the following request:
			aql:self.eClass().eAllReferences (or self.eClass().eAllAttributes to retrieve attributes)

			<br/>
			<br/>

			<img height="300" width="550" border="0" src="Images/12_5_ Acceleo Queries_html_m4a26b2e2.png"/>
			<br/>

			<br/>
			One easiest way to retrieve references or attributes is to open the Properties View and go the Expert tab then choose relevant references/attributes for your query

			<br/>
			<br/>

			<img height="250" width="800" border="0" src="Images/12_5_ Acceleo Queries_html_m44230212.png"/>
			<br/>
			<br/>
			You just have to write the reference name in a camelCaseFormat to use it with Aql (e.g. Available In States =&gt; availableInStates) or in some case with the corresponding getter function
		</p>
	</body>
</html>